package org.mch.func.db.pdmfile;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.io.File;
import java.util.List;

import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.filechooser.FileFilter;

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.mch.biz.ui.FuncEvent;
import org.mch.biz.ui.FuncPanel;
import org.mch.swingm.ext.METextField;

public class PDMPanel extends FuncPanel {
	private static final long serialVersionUID = -3517284290131816053L;

	private JSplitPane splitPane;
	private JPanel panel;
	private JPanel panel_1;
	private JButton button_loadpdm;
	private JButton button_selectpdm;
	private JTextField textField_pdm;
	private JButton btn_javabean;
	private JScrollPane scrollPane;
	private JTextArea textArea_newmethod;
	private JFileChooser selectPdmFile;
	private List<PDMTableObject> pdmTableList;
	private JRadioButton rdbtnJavabean;
	private JRadioButton rdbtnHibernatevo;
	private JRadioButton rBtnJpaEntity;
	private ButtonGroup btngropBean;
	private ButtonGroup btngropNewTs;
	private JLabel lblBeanClassType;
	private JLabel lblBeanFieldType;
	private JRadioButton rdbtnPublic;
	private JRadioButton rdbtnProtected;
	private JRadioButton rdbtnPrivate;
	private ButtonGroup btngropField;
	private JRadioButton rBtnBaseEO;
	private JScrollPane scrollPane_1;
	private RSyntaxTextArea textArea_right;
	private JLabel lblTs;
	private JRadioButton rdbtn_newts;
	private JRadioButton rdbtn_notnewts;
	private JScrollPane scrollPane_2;
	private JList<String> list_pdm;
	private JLabel label_1;
	private JTextField textPackage;
	private JLabel label_2;
	private JTextField textAuthor;
	private JRadioButton radioBtnEntityEO;
	private METextField textExtendEO;
	private METextField textClassName;

	public PDMPanel() {
		initComponents();
	}

	private void initComponents() {
		setLayout(new BorderLayout(0, 0));
		add(getSplitPane(), "Center");
	}

	public JSplitPane getSplitPane() {
		if (this.splitPane == null) {
			this.splitPane = new JSplitPane();
			this.splitPane.setRightComponent(getPanel_1());
			this.splitPane.setLeftComponent(getPanel());
			this.splitPane.setDividerLocation(300);
		}
		return this.splitPane;
	}

	public JPanel getPanel() {
		if (this.panel == null) {
			this.panel = new JPanel();
			this.panel.setFont(new Font("宋体", 0, 16));
			this.panel.setLayout(null);
			this.panel.add(getButton_loadpdm());
			this.panel.add(getButton_selectpdm());
			this.panel.add(getTextField_pdm());
			this.panel.add(getBtn_javabean());
			this.panel.add(getRdbtnJavabean());
			this.panel.add(getRdbtnHibernatevo());
			this.panel.add(getRBtnJpaEntity());

			getBtngropBean().add(getRdbtnJavabean());
			getBtngropBean().add(getRdbtnHibernatevo());
			getBtngropBean().add(getRBtnJpaEntity());
			getBtngropBean().add(getRBtnBaseEO());
			getBtngropBean().add(getRadioBtnEntityEO());

			this.panel.add(getLblBeanClassType());
			this.panel.add(getLblBeanFieldType());
			this.panel.add(getRdbtnPublic());
			this.panel.add(getRdbtnProtected());
			this.panel.add(getRdbtnPrivate());
			getBtngropField().add(getRdbtnPublic());
			getBtngropField().add(getRdbtnProtected());
			getBtngropField().add(getRdbtnPrivate());

			getBtngropNewTs().add(getRdbtn_newts());
			getBtngropNewTs().add(getRdbtn_notnewts());

			this.panel.add(getRBtnBaseEO());
			panel.add(getLblTs());
			panel.add(getRdbtn_newts());
			panel.add(getRdbtn_notnewts());
			panel.add(getScrollPane_2());
			panel.add(getLabel_1());
			panel.add(getTextPackage());
			panel.add(getLabel_2());
			panel.add(getTextAuthor());
			panel.add(getRadioBtnEntityEO());
			panel.add(getTextExtendEO());
			panel.add(getTextClassName());

		}
		return this.panel;
	}

	public JPanel getPanel_1() {
		if (this.panel_1 == null) {
			this.panel_1 = new JPanel();
			this.panel_1.setLayout(new BorderLayout(0, 0));
			this.panel_1.add(getScrollPane_1(), "Center");
		}
		return this.panel_1;
	}

	protected JButton getButton_loadpdm() {
		if (this.button_loadpdm == null) {
			this.button_loadpdm = new JButton("加载");
			this.button_loadpdm.addActionListener(getEvent());
			this.button_loadpdm.setToolTipText("加载PDM文件中表！");
			this.button_loadpdm.setBounds(205, 43, 78, 25);
		}
		return this.button_loadpdm;
	}

	protected JButton getButton_selectpdm() {
		if (this.button_selectpdm == null) {
			this.button_selectpdm = new JButton("选择");
			this.button_selectpdm.addActionListener(getEvent());
			this.button_selectpdm.setToolTipText("选择PDM文件");
			this.button_selectpdm.setBounds(205, 8, 78, 25);
		}
		return this.button_selectpdm;
	}

	protected JTextField getTextField_pdm() {
		if (this.textField_pdm == null) {
			this.textField_pdm = new JTextField();
			this.textField_pdm.setBounds(10, 10, 185, 21);
			this.textField_pdm.setColumns(10);
		}
		return this.textField_pdm;
	}

	protected JButton getBtn_javabean() {
		if (this.btn_javabean == null) {
			this.btn_javabean = new JButton("Build Bean");
			this.btn_javabean.addActionListener(getEvent());
			this.btn_javabean.setToolTipText("生成JavaBean");
			this.btn_javabean.setBounds(162, 461, 121, 25);
		}
		return this.btn_javabean;
	}

	protected JScrollPane getScrollPane() {
		if (this.scrollPane == null) {
			this.scrollPane = new JScrollPane();
			this.scrollPane.setViewportView(getTextArea_newmethod());
		}
		return this.scrollPane;
	}

	protected JTextArea getTextArea_newmethod() {
		if (this.textArea_newmethod == null) {
			this.textArea_newmethod = new JTextArea();
		}
		return this.textArea_newmethod;
	}

	public JFileChooser getSelectPdmFile() {
		if (this.selectPdmFile == null) {
			this.selectPdmFile = new JFileChooser();
			this.selectPdmFile.removeChoosableFileFilter(this.selectPdmFile.getFileFilter());
			this.selectPdmFile.setPreferredSize(new Dimension(700, 400));
			this.selectPdmFile.setFileFilter(new FileFilter() {
				@Override
				public String getDescription() {
					return "PDM文件";
				}

				@Override
				public boolean accept(File f) {
					if (f.isDirectory() || f.getName().toLowerCase().endsWith("pdm")) {
						return true;
					} else {
						return false;
					}
				}
			});
			this.selectPdmFile.setDialogTitle("选择PDM文件！");
		}
		return this.selectPdmFile;
	}

	public List<PDMTableObject> getPdmTableList() {
		return this.pdmTableList;
	}

	public void setPdmTableList(List<PDMTableObject> pdmTableList) {
		this.pdmTableList = pdmTableList;
	}

	protected JRadioButton getRdbtnJavabean() {
		if (this.rdbtnJavabean == null) {
			this.rdbtnJavabean = new JRadioButton("JavaBean");
			rdbtnJavabean.setSelected(true);
			this.rdbtnJavabean.setBounds(10, 382, 98, 23);
		}
		return this.rdbtnJavabean;
	}

	protected JRadioButton getRdbtnHibernatevo() {
		if (this.rdbtnHibernatevo == null) {
			this.rdbtnHibernatevo = new JRadioButton("HibernateVO");
			this.rdbtnHibernatevo.setBounds(10, 407, 103, 23);
		}
		return this.rdbtnHibernatevo;
	}

	protected JRadioButton getRBtnJpaEntity() {
		if (this.rBtnJpaEntity == null) {
			this.rBtnJpaEntity = new JRadioButton("JPAEntity");
			this.rBtnJpaEntity.setBounds(10, 432, 98, 23);
		}
		return this.rBtnJpaEntity;
	}

	protected JLabel getLblBeanClassType() {
		if (this.lblBeanClassType == null) {
			this.lblBeanClassType = new JLabel("Bean 类型：");
			this.lblBeanClassType.setBounds(10, 361, 121, 15);
		}
		return this.lblBeanClassType;
	}

	protected JLabel getLblBeanFieldType() {
		if (this.lblBeanFieldType == null) {
			this.lblBeanFieldType = new JLabel("Bean Field 修饰符：");
			this.lblBeanFieldType.setToolTipText("Bean字段修饰符，如：public int a;private int a;");
			this.lblBeanFieldType.setBounds(141, 358, 142, 15);
		}
		return this.lblBeanFieldType;
	}

	protected JRadioButton getRdbtnPublic() {
		if (this.rdbtnPublic == null) {
			this.rdbtnPublic = new JRadioButton("public");
			this.rdbtnPublic.setBounds(141, 382, 121, 23);
		}
		return this.rdbtnPublic;
	}

	protected JRadioButton getRdbtnProtected() {
		if (this.rdbtnProtected == null) {
			this.rdbtnProtected = new JRadioButton("protected");
			this.rdbtnProtected.setBounds(141, 407, 121, 23);
		}
		return this.rdbtnProtected;
	}

	protected JRadioButton getRdbtnPrivate() {
		if (this.rdbtnPrivate == null) {
			this.rdbtnPrivate = new JRadioButton("private");
			rdbtnPrivate.setSelected(true);
			this.rdbtnPrivate.setBounds(141, 432, 121, 23);
		}
		return this.rdbtnPrivate;
	}

	public ButtonGroup getBtngropBean() {
		if (this.btngropBean == null) {
			this.btngropBean = new ButtonGroup();
		}
		return this.btngropBean;
	}

	public ButtonGroup getBtngropNewTs() {
		if (this.btngropNewTs == null) {
			this.btngropNewTs = new ButtonGroup();
		}
		return this.btngropNewTs;
	}

	public ButtonGroup getBtngropField() {
		if (this.btngropField == null) {
			this.btngropField = new ButtonGroup();
		}
		return this.btngropField;
	}

	protected JRadioButton getRBtnBaseEO() {
		if (this.rBtnBaseEO == null) {
			this.rBtnBaseEO = new JRadioButton("BaseEO(mch)");
			this.rBtnBaseEO.setBounds(10, 457, 121, 23);
		}
		return this.rBtnBaseEO;
	}

	public JScrollPane getScrollPane_1() {
		if (this.scrollPane_1 == null) {
			this.scrollPane_1 = new JScrollPane();
			this.scrollPane_1.setViewportView(getTextArea_right());
		}
		return this.scrollPane_1;
	}

	public RSyntaxTextArea getTextArea_right() {
		if (this.textArea_right == null) {
			this.textArea_right = new RSyntaxTextArea();
			this.textArea_right.setFont(new Font("宋体", 0, 14));
			this.textArea_right.setBorder(new EtchedBorder(0, null, null));
			this.textArea_right.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
		}
		return this.textArea_right;
	}

	@Override
	protected FuncEvent createEvent() {
		return new PDMPanelEvent(this);
	}

	public JLabel getLblTs() {
		if (lblTs == null) {
			lblTs = new JLabel("TS（时间戳）：");
			lblTs.setBounds(10, 307, 98, 15);
		}
		return lblTs;
	}

	public JRadioButton getRdbtn_newts() {
		if (rdbtn_newts == null) {
			rdbtn_newts = new JRadioButton("生成TS");
			rdbtn_newts.setBounds(10, 328, 78, 23);
		}
		return rdbtn_newts;
	}

	public JRadioButton getRdbtn_notnewts() {
		if (rdbtn_notnewts == null) {
			rdbtn_notnewts = new JRadioButton("不生成TS");
			rdbtn_notnewts.setSelected(true);
			rdbtn_notnewts.setBounds(92, 328, 121, 23);
		}
		return rdbtn_notnewts;
	}

	public JScrollPane getScrollPane_2() {
		if (scrollPane_2 == null) {
			scrollPane_2 = new JScrollPane();
			scrollPane_2.setBounds(10, 41, 185, 143);
			scrollPane_2.setViewportView(getList_pdm());
		}
		return scrollPane_2;
	}

	public JList<String> getList_pdm() {
		if (list_pdm == null) {
			list_pdm = new JList<String>();
			list_pdm.setModel(new DefaultListModel<String>());
		}
		return list_pdm;
	}

	public JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel("包名：");
			label_1.setBounds(10, 251, 54, 15);
		}
		return label_1;
	}

	public JTextField getTextPackage() {
		if (textPackage == null) {
			textPackage = new JTextField();
			textPackage.setColumns(10);
			textPackage.setBounds(92, 248, 191, 21);
		}
		return textPackage;
	}

	public JLabel getLabel_2() {
		if (label_2 == null) {
			label_2 = new JLabel("作者：");
			label_2.setBounds(10, 276, 54, 15);
		}
		return label_2;
	}

	public JTextField getTextAuthor() {
		if (textAuthor == null) {
			textAuthor = new JTextField();
			textAuthor.setColumns(10);
			textAuthor.setBounds(92, 273, 191, 21);
		}
		return textAuthor;
	}

	public JRadioButton getRadioBtnEntityEO() {
		if (radioBtnEntityEO == null) {
			radioBtnEntityEO = new JRadioButton("EntityEO");
			radioBtnEntityEO.setBounds(10, 482, 98, 23);
		}
		return radioBtnEntityEO;
	}
	public METextField getTextExtendEO() {
		if (textExtendEO == null) {
			textExtendEO = new METextField();
			textExtendEO.getLabel().setText("EO继承类：");
			textExtendEO.setBounds(10, 196, 273, 20);
		}
		return textExtendEO;
	}
	public METextField getTextClassName() {
		if (textClassName == null) {
			textClassName = new METextField();
			textClassName.getLabel().setText("指定类名：");
			textClassName.setBounds(10, 219, 273, 20);
		}
		return textClassName;
	}
}